﻿using Microsoft.CSharp.Activities;
using System;
using System.Activities;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WFExtended.Twitter.Activities.Designers;

namespace WFExtended.Twitter.Activities
{
    /// <summary>
    /// Provides a simple, relevance-based search interface to public user accounts on Twitter.
    /// </summary>
    [ToolboxBitmapAttribute(typeof(EntryPoint), "Resources.UsersToolbox.bmp")]
    [Designer(typeof(UsersDesigner))]
    [Description("Provides a simple, relevance-based search interface to public user accounts on Twitter.")]
    public class SearchUsers : TwitterOperationInvoker<List<User>>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="SearchUsers"/> class.
        /// </summary>
        public SearchUsers()
            : base("SearchUsers")
        {
            Page = new InArgument<int>(new CSharpValue<int>("0"));
            Count = new InArgument<int>(new CSharpValue<int>("20"));
            IncludeEntities = new InArgument<bool>(new CSharpValue<bool>("true"));
        }


        /// <summary>
        /// The search query to run against people search.
        /// <remarks>
        /// Required Argument
        /// </remarks>
        /// </summary>
        /// <value>
        /// The query.
        /// </value>
        [Browsable(true)]
        [Category("Properties")]
        [RequiredArgument]
        [Description("The search query to run against people search.")]
        public InArgument<string> Query { get; set; }

        /// <summary>
        /// Specifies the page of results to retrieve.
        /// </summary>
        /// <value>
        /// The page.
        /// </value>
        [Browsable(true)]
        [Category("Navigation")]
        [RequiredArgument]
        [Description("Specifies the page of results to retrieve.")]
        public InArgument<int> Page { get; set; }

        /// <summary>
        /// The number of potential user results to retrieve per page. This value has a maximum of 20.
        /// </summary>
        /// <value>
        /// The count.
        /// </value>
        [Browsable(true)]
        [Category("Navigation")]
        [RequiredArgument]
        [Description("The number of potential user results to retrieve per page. This value has a maximum of 20.")]
        public InArgument<int> Count { get; set; }

        /// <summary>
        /// The entities node will be omitted when set to false.
        /// </summary>
        /// <value>
        /// The include entities.
        /// </value>
        [Browsable(true)]
        [Category("Properties")]
        [RequiredArgument]
        [Description("The entities node will be omitted when set to false.")]
        public InArgument<bool> IncludeEntities { get; set; }

        /// <summary>
        /// Caches the metadata.
        /// </summary>
        /// <param name="metadata">The metadata.</param>
        protected override void CacheMetadata(System.Activities.NativeActivityMetadata metadata)
        {
            RuntimeArgument queryArgument = new RuntimeArgument("Query", typeof(string), ArgumentDirection.In, true);
            metadata.Bind(Query, queryArgument);
            metadata.AddArgument(queryArgument);

            RuntimeArgument pageArgument = new RuntimeArgument("Page", typeof(int), ArgumentDirection.In, true);
            metadata.Bind(Page, pageArgument);
            metadata.AddArgument(pageArgument);

            RuntimeArgument countArgument = new RuntimeArgument("Count", typeof(int), ArgumentDirection.In, true);
            metadata.Bind(Count, countArgument);
            metadata.AddArgument(countArgument);

            RuntimeArgument includeEntitiesArgument = new RuntimeArgument("IncludeEntities", typeof(bool), ArgumentDirection.In, true);
            metadata.Bind(IncludeEntities, includeEntitiesArgument);
            metadata.AddArgument(includeEntitiesArgument);

            base.CacheMetadata(metadata);
        }

        /// <summary>
        /// Executes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        protected override void Execute(System.Activities.NativeActivityContext context)
        {
            Parameters.Clear();

            Parameters.Add("query", Query);
            Parameters.Add("page", Page);
            Parameters.Add("count", Count);
            Parameters.Add("includeEntities", IncludeEntities);

            base.Execute(context);
        }
    }
}
